/**
*这个保存基本的按键信息，WASDJKLI上下左右
*/

package kgame5.kutil {
import flash.display.*;
import flash.events.*;
import flash.ui.*;

public class KKey {
	
	//keyCode
	public static const 
		KEYCODE_0:int=48,
		KEYCODE_1:int=49,
		KEYCODE_2:int=50,
		KEYCODE_3:int=51,
		KEYCODE_4:int=52,
		KEYCODE_5:int=53,
		KEYCODE_6:int=54,
		KEYCODE_7:int=55,
		KEYCODE_8:int=56,
		KEYCODE_9:int=57,
		
	
		KEYCODE_Z:int=90,
		KEYCODE_X:int=88,
		KEYCODE_C:int=67,
		KEYCODE_V:int=86,
		KEYCODE_B:int=66,
		KEYCODE_N:int=78,
		KEYCODE_M:int=77;
	
	public static const 
		NUMBASE:int=48;//1~49,2~50...9~(48+9)
	
	public static var 
		isDown_W:Boolean=false,
		isDown_S:Boolean=false,
		isDown_A:Boolean=false,
		isDown_D:Boolean=false,
		
		isDown_J:Boolean=false,
		isDown_K:Boolean=false,
		isDown_L:Boolean=false,
		isDown_I:Boolean=false,
		
		isDown_UP:Boolean=false,
		isDown_DOWN:Boolean=false,
		isDown_LEFT:Boolean=false,
		isDown_RIGHT:Boolean=false,
		
		isDown_X:Boolean=false,
		isDown_Z:Boolean=false,
		
		isDown_LL:Boolean=false,//<
		isDown_RR:Boolean=false,//>
		
		isDown_SPACE:Boolean=false,
		isDown_ENTER:Boolean=false;
	
	//清除输入
	public static function Clear(){
		isDown_W=false;
		isDown_S=false;
		isDown_A=false;
		isDown_D=false;
		
		isDown_J=false;
		isDown_K=false;
		isDown_L=false;
		isDown_I=false;
		
		isDown_UP=false;
		isDown_DOWN=false;
		isDown_LEFT=false;
		isDown_RIGHT=false;
		
		isDown_X=false;
		isDown_Z=false;
		
		isDown_LL=false;
		isDown_RR=false;
		
		isDown_SPACE=false;
		
		isDown_ENTER=false;
		
		//stage.removeEventListener(KeyboardEvent.KEY_DOWN,OnKeyDown);
		//stage.removeEventListener(KeyboardEvent.KEY_UP,OnKeyUp);
	}
	public static function Init(stage:Stage){
		stage.addEventListener(KeyboardEvent.KEY_DOWN,OnKeyDown);
		stage.addEventListener(KeyboardEvent.KEY_UP,OnKeyUp);
	}

//==================响应输入======================
private static function OnKeyDown(e:KeyboardEvent):void{
		
		//--
		//*
		//T.p("dwn:"+e.keyCode);
		switch(e.keyCode){
			//上下左右
			case Keyboard.LEFT:
				KKey.isDown_LEFT=true;
			break;
			case Keyboard.RIGHT:
				KKey.isDown_RIGHT=true;
			break;
			case Keyboard.UP:
				KKey.isDown_UP=true;
			break;
			case Keyboard.DOWN:
				KKey.isDown_DOWN=true;
			break;
			
			//WASD
			case 87://W
				KKey.isDown_W=true;
			break;
			case 65://A
				KKey.isDown_A=true;
			break;
			case 83://S
				KKey.isDown_S=true;
			break;
			case 68://D
				KKey.isDown_D=true;
			break;
			
			//JKLI
			case 74://J
				KKey.isDown_J=true;
			break;
			case 75://K
				KKey.isDown_K=true;
			break;
			case 76://L
				KKey.isDown_L=true;
			break;
			case 73://I
				KKey.isDown_I=true;
			break;
			
			//XZ
			case 90://Z
				KKey.isDown_Z=true;
			break;
			case 88://X
				KKey.isDown_X=true;
			break;
			
			//< >
			case 188://<
				KKey.isDown_LL=true;
			break;
			case 190://>
				KKey.isDown_RR=true;
			break;
			
			//SPACE
			case 32://D
				KKey.isDown_SPACE=true;
			break;
			
			//ENTER
			case 13://D
				KKey.isDown_ENTER=true;
			break;
		}
		//*/
	}
private static function OnKeyUp(e:KeyboardEvent):void{
		
		//--
		switch(e.keyCode){
			//上下左右
			case Keyboard.LEFT:
				KKey.isDown_LEFT=false;
			break;
			case Keyboard.RIGHT:
				KKey.isDown_RIGHT=false;
			break;
			case Keyboard.UP:
				KKey.isDown_UP=false;
			break;
			case Keyboard.DOWN:
				KKey.isDown_DOWN=false;
			break;
			
			//WASD
			case 87://W
				KKey.isDown_W=false;
			break;
			case 65://A
				KKey.isDown_A=false;
			break;
			case 83://S
				KKey.isDown_S=false;
			break;
			case 68://D
				KKey.isDown_D=false;
			break;
			
			//JKLI
			case 74://J
				KKey.isDown_J=false;
			break;
			case 75://K
				KKey.isDown_K=false;
			break;
			case 76://L
				KKey.isDown_L=false;
				
			break;
			case 73://I
				KKey.isDown_I=false;
				
			break;
			
			//ZX
			case 90://Z
				KKey.isDown_Z=false;
			break;
			case 88://X
				KKey.isDown_X=false;
			
			//< >
			case 188://<
				KKey.isDown_LL=false;
			break;
			case 190://>
				KKey.isDown_RR=false;
			break;
				
			//SPACE
			case 32://D
				KKey.isDown_SPACE=false;
				
			break;
			
			//ENTER
			case 13://D
				KKey.isDown_ENTER=false;
			break;
		}
	}
}//end of class
}